package com.ftg.learn.springbootmq.work.Producer;

import com.ftg.learn.springbootmq.work.entity.StudentEntity;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 工作队列消息生产者
 */
@Component
@Slf4j
public class MessageProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送字符串消息
     */
    public void sendStringMessage(String message, String operator) {
        Map<String, Object> map = new HashMap<>();
        map.put("body", message);
        map.put("operator", operator);

        rabbitTemplate.convertAndSend("work.queue", map);
    }

    /**
     * 发送学生实体消息
     */
    public void sendStructuredMessage(StudentEntity content, String operator) {
        Map<String, Object> map = new HashMap<>();
        map.put("body", content);
        map.put("operator", operator);

        rabbitTemplate.convertAndSend("work.queue", map);
    }
}
